package com.ease.common.util;

import java.util.Iterator;
import java.util.Map;

import org.apache.commons.beanutils.BeanUtils;

import com.ease.common.exception.NestedException;

/**
 * 
 * @author nathanleewei
 * 
 */
@Deprecated
/* rename as BeanUtil */
public abstract class ObjectUtil extends Detect {

	/**
	 * 拷贝对象 (不是深度拷贝)
	 */
	public static void copyProperties(Object source, Object target) {
		try {
			org.springframework.beans.BeanUtils.copyProperties(source, target);
		} catch (Exception ex) {
			throw new NestedException("source: " + source + ",target: " + target, ex);
		}
	}

	/**
	 * 一个对象中是否包括map中的属性
	 * 
	 * @param source
	 * @param map
	 */
	@SuppressWarnings("unchecked")
	public static boolean contains(Object source, Map<String, Object> map) {
		try {
			Map<String, Object> sourceMap = BeanUtils.describe(source);

			for (Iterator<String> it = map.keySet().iterator(); it.hasNext();) {
				String key = it.next();
				if (!(null != map.get(key) && map.get(key).equals(sourceMap.get(key)))) {
					return false;
				}
			}
			return true;
		} catch (Exception ex) {
			throw new NestedException("source: " + source + ",target: " + map, ex);
		}
	}
}
